package com.asmtest.visitor;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Opcodes;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

/**
 * @author yutianhong
 * @version 1.0
 * @since 2023/11/28 17:18
 */
public class CustomAnnotationVisitor extends AnnotationVisitor {
    private final Map<String, Object> map = new HashMap<>();
    private final Consumer<Map<String, Object>> consumer;

    public CustomAnnotationVisitor(Consumer<Map<String, Object>> consumer) {
        super(Opcodes.ASM9);
        this.consumer = consumer;
    }

    @Override
    public void visit(String name, Object value) {
        map.put(name, value);
    }

    @Override
    public void visitEnd() {
        consumer.accept(map);
    }
}
